import { Injectable } from '@nestjs/common';
import { randomBytes } from 'crypto';
import * as fs from 'fs'; // 用于调试保存文件

const SIZE = 5
const NDOTS = 100
const GIF_SIZE = 17646
const LETTERS = 'abcdafahijklmnopqrstuvwxyz'
const SW = [0, 4, 8, 12, 16, 20, 23, 27, 31, 35, 39, 43, 47, 50, 54, 58, 61, 65, 68, 71, 75, 78, 81, 84, 87, 90, 93, 96, 98, 101, 103, 105, 108, 110, 112, 114, 115, 117, 119, 120, 121, 122, 123, 124, 125, 126, 126, 127, 127, 127, 127, 127, 127, 127, 126, 126, 125, 124, 123, 122, 121, 120, 119, 117, 115, 114, 112, 110, 108, 105, 103, 101, 98, 96, 93, 90, 87, 84, 81, 78, 75, 71, 68, 65, 61, 58, 54, 50, 47, 43, 39, 35, 31, 27, 23, 20, 16, 12, 8, 4, 0, -4, -8, -12, -16, -20, -23, -27, -31, -35, -39, -43, -47, -50, -54, -58, -61, -65, -68, -71, -75, -78, -81, -84, -87, -90, -93, -96, -98, -101, -103, -105, -108, -110, -112, -114, -115, -117, -119, -120, -121, -122, -123, -124, -125, -126, -126, -127, -127, -127, -127, -127, -127, -127, -126, -126, -125, -124, -123, -122, -121, -120, -119, -117, -115, -114, -112, -110, -108, -105, -103, -101, -98, -96, -93, -90, -87, -84, -81, -78, -75, -71, -68, -65, -61, -58, -54, -50, -47, -43, -39, -35, -31, -27, -23, -20, -16, -12, -8, -4]
// Colors from
// https://material.io/guidelines/style/color.html#color-ui-color-palette
const colors = [
  // Black 500 #000000
  `GIF89a\xc8\0\x46\0\x83\0\0
\x11\x11\x11
\x11\x11\x11
\x11\x11\x11
\x11\x11\x11
\x11\x11\x11
\x11\x11\x11
\x11\x11\x11
\x11\x11\x11
\x11\x11\x11
\x11\x11\x11
\x11\x11\x11
\x11\x11\x11
\x11\x11\x11
\x11\x11\x11
\x11\x11\x11
\xff\xff\xff,\0\0\0\0\xc8\0\x46\0\0\x04`,

  // Red 500 #F44336
  `GIF89a\xc8\0\x46\0\x83\0\0
\xF4\x43\x36
\xF4\x43\x36
\xF4\x43\x36
\xF4\x43\x36
\xF4\x43\x36
\xF4\x43\x36
\xF4\x43\x36
\xF4\x43\x36
\xF4\x43\x36
\xF4\x43\x36
\xF4\x43\x36
\xF4\x43\x36
\xF4\x43\x36
\xF4\x43\x36
\xF4\x43\x36
\xff\xff\xff,\0\0\0\0\xc8\0\x46\0\0\x04`,

  // Pink 500 #E91E63
  `GIF89a\xc8\0\x46\0\x83\0\0
\xE9\x1E\x63
\xE9\x1E\x63
\xE9\x1E\x63
\xE9\x1E\x63
\xE9\x1E\x63
\xE9\x1E\x63
\xE9\x1E\x63
\xE9\x1E\x63
\xE9\x1E\x63
\xE9\x1E\x63
\xE9\x1E\x63
\xE9\x1E\x63
\xE9\x1E\x63
\xE9\x1E\x63
\xE9\x1E\x63
\xff\xff\xff,\0\0\0\0\xc8\0\x46\0\0\x04`,

  // Purple 500 #9C27B0
  `GIF89a\xc8\0\x46\0\x83\0\0
\x9C\x27\xB0
\x9C\x27\xB0
\x9C\x27\xB0
\x9C\x27\xB0
\x9C\x27\xB0
\x9C\x27\xB0
\x9C\x27\xB0
\x9C\x27\xB0
\x9C\x27\xB0
\x9C\x27\xB0
\x9C\x27\xB0
\x9C\x27\xB0
\x9C\x27\xB0
\x9C\x27\xB0
\x9C\x27\xB0
\xff\xff\xff,\0\0\0\0\xc8\0\x46\0\0\x04`,

  // Deep Purple 500 #673AB7
  `GIF89a\xc8\0\x46\0\x83\0\0
\x67\x3A\xB7
\x67\x3A\xB7
\x67\x3A\xB7
\x67\x3A\xB7
\x67\x3A\xB7
\x67\x3A\xB7
\x67\x3A\xB7
\x67\x3A\xB7
\x67\x3A\xB7
\x67\x3A\xB7
\x67\x3A\xB7
\x67\x3A\xB7
\x67\x3A\xB7
\x67\x3A\xB7
\x67\x3A\xB7
\xff\xff\xff,\0\0\0\0\xc8\0\x46\0\0\x04`,

  // Indigo 500 #3F51B5
  `GIF89a\xc8\0\x46\0\x83\0\0
\x3F\x51\xB5
\x3F\x51\xB5
\x3F\x51\xB5
\x3F\x51\xB5
\x3F\x51\xB5
\x3F\x51\xB5
\x3F\x51\xB5
\x3F\x51\xB5
\x3F\x51\xB5
\x3F\x51\xB5
\x3F\x51\xB5
\x3F\x51\xB5
\x3F\x51\xB5
\x3F\x51\xB5
\x3F\x51\xB5
\xff\xff\xff,\0\0\0\0\xc8\0\x46\0\0\x04`,

  // Blue 500 #2196F3
  `GIF89a\xc8\0\x46\0\x83\0\0
\x21\x96\xF3
\x21\x96\xF3
\x21\x96\xF3
\x21\x96\xF3
\x21\x96\xF3
\x21\x96\xF3
\x21\x96\xF3
\x21\x96\xF3
\x21\x96\xF3
\x21\x96\xF3
\x21\x96\xF3
\x21\x96\xF3
\x21\x96\xF3
\x21\x96\xF3
\x21\x96\xF3
\xff\xff\xff,\0\0\0\0\xc8\0\x46\0\0\x04`,

  // Light Blue 500 #03A9F4
  `GIF89a\xc8\0\x46\0\x83\0\0
\x03\xA9\xF4
\x03\xA9\xF4
\x03\xA9\xF4
\x03\xA9\xF4
\x03\xA9\xF4
\x03\xA9\xF4
\x03\xA9\xF4
\x03\xA9\xF4
\x03\xA9\xF4
\x03\xA9\xF4
\x03\xA9\xF4
\x03\xA9\xF4
\x03\xA9\xF4
\x03\xA9\xF4
\x03\xA9\xF4
\xff\xff\xff,\0\0\0\0\xc8\0\x46\0\0\x04`,

  // Cyan 500 #00BCD4
  `GIF89a\xc8\0\x46\0\x83\0\0
\x00\xBC\xD4
\x00\xBC\xD4
\x00\xBC\xD4
\x00\xBC\xD4
\x00\xBC\xD4
\x00\xBC\xD4
\x00\xBC\xD4
\x00\xBC\xD4
\x00\xBC\xD4
\x00\xBC\xD4
\x00\xBC\xD4
\x00\xBC\xD4
\x00\xBC\xD4
\x00\xBC\xD4
\x00\xBC\xD4
\xff\xff\xff,\0\0\0\0\xc8\0\x46\0\0\x04`,

  // Teal 500 #009688
  `GIF89a\xc8\0\x46\0\x83\0\0
\x00\x96\x88
\x00\x96\x88
\x00\x96\x88
\x00\x96\x88
\x00\x96\x88
\x00\x96\x88
\x00\x96\x88
\x00\x96\x88
\x00\x96\x88
\x00\x96\x88
\x00\x96\x88
\x00\x96\x88
\x00\x96\x88
\x00\x96\x88
\x00\x96\x88
\xff\xff\xff,\0\0\0\0\xc8\0\x46\0\0\x04`,

  // Green 500 #4CAF50
  `GIF89a\xc8\0\x46\0\x83\0\0
\x4C\xAF\x50
\x4C\xAF\x50
\x4C\xAF\x50
\x4C\xAF\x50
\x4C\xAF\x50
\x4C\xAF\x50
\x4C\xAF\x50
\x4C\xAF\x50
\x4C\xAF\x50
\x4C\xAF\x50
\x4C\xAF\x50
\x4C\xAF\x50
\x4C\xAF\x50
\x4C\xAF\x50
\x4C\xAF\x50
\xff\xff\xff,\0\0\0\0\xc8\0\x46\0\0\x04`,

  // Light Green 500 #8BC34A
  `GIF89a\xc8\0\x46\0\x83\0\0
\x8B\xC3\x4A
\x8B\xC3\x4A
\x8B\xC3\x4A
\x8B\xC3\x4A
\x8B\xC3\x4A
\x8B\xC3\x4A
\x8B\xC3\x4A
\x8B\xC3\x4A
\x8B\xC3\x4A
\x8B\xC3\x4A
\x8B\xC3\x4A
\x8B\xC3\x4A
\x8B\xC3\x4A
\x8B\xC3\x4A
\x8B\xC3\x4A
\xff\xff\xff,\0\0\0\0\xc8\0\x46\0\0\x04`,

  // Lime 500 #CDDC39
  `GIF89a\xc8\0\x46\0\x83\0\0
\xCD\xDC\x39
\xCD\xDC\x39
\xCD\xDC\x39
\xCD\xDC\x39
\xCD\xDC\x39
\xCD\xDC\x39
\xCD\xDC\x39
\xCD\xDC\x39
\xCD\xDC\x39
\xCD\xDC\x39
\xCD\xDC\x39
\xCD\xDC\x39
\xCD\xDC\x39
\xCD\xDC\x39
\xCD\xDC\x39
\xff\xff\xff,\0\0\0\0\xc8\0\x46\0\0\x04`,

  // Yellow 500 #FFEB3B
  `GIF89a\xc8\0\x46\0\x83\0\0
\xFF\xEB\x3B
\xFF\xEB\x3B
\xFF\xEB\x3B
\xFF\xEB\x3B
\xFF\xEB\x3B
\xFF\xEB\x3B
\xFF\xEB\x3B
\xFF\xEB\x3B
\xFF\xEB\x3B
\xFF\xEB\x3B
\xFF\xEB\x3B
\xFF\xEB\x3B
\xFF\xEB\x3B
\xFF\xEB\x3B
\xFF\xEB\x3B
\xff\xff\xff,\0\0\0\0\xc8\0\x46\0\0\x04`,

  // Amber 500 #FFC107
  `GIF89a\xc8\0\x46\0\x83\0\0
\xFF\xC1\x07
\xFF\xC1\x07
\xFF\xC1\x07
\xFF\xC1\x07
\xFF\xC1\x07
\xFF\xC1\x07
\xFF\xC1\x07
\xFF\xC1\x07
\xFF\xC1\x07
\xFF\xC1\x07
\xFF\xC1\x07
\xFF\xC1\x07
\xFF\xC1\x07
\xFF\xC1\x07
\xFF\xC1\x07
\xff\xff\xff,\0\0\0\0\xc8\0\x46\0\0\x04`,

  // Orange 500 #FF9800
  `GIF89a\xc8\0\x46\0\x83\0\0
\xFF\x98\x00
\xFF\x98\x00
\xFF\x98\x00
\xFF\x98\x00
\xFF\x98\x00
\xFF\x98\x00
\xFF\x98\x00
\xFF\x98\x00
\xFF\x98\x00
\xFF\x98\x00
\xFF\x98\x00
\xFF\x98\x00
\xFF\x98\x00
\xFF\x98\x00
\xFF\x98\x00
\xff\xff\xff,\0\0\0\0\xc8\0\x46\0\0\x04`,

  // Deep Orange 500 #FF5722
  `GIF89a\xc8\0\x46\0\x83\0\0
\xFF\x57\x22
\xFF\x57\x22
\xFF\x57\x22
\xFF\x57\x22
\xFF\x57\x22
\xFF\x57\x22
\xFF\x57\x22
\xFF\x57\x22
\xFF\x57\x22
\xFF\x57\x22
\xFF\x57\x22
\xFF\x57\x22
\xFF\x57\x22
\xFF\x57\x22
\xFF\x57\x22
\xff\xff\xff,\0\0\0\0\xc8\0\x46\0\0\x04`,

  // Brown 500 #795548
  `GIF89a\xc8\0\x46\0\x83\0\0
\x79\x55\x48
\x79\x55\x48
\x79\x55\x48
\x79\x55\x48
\x79\x55\x48
\x79\x55\x48
\x79\x55\x48
\x79\x55\x48
\x79\x55\x48
\x79\x55\x48
\x79\x55\x48
\x79\x55\x48
\x79\x55\x48
\x79\x55\x48
\x79\x55\x48
\xff\xff\xff,\0\0\0\0\xc8\0\x46\0\0\x04`
]

const lt0 = [-100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -4, 11, 7, 5, 3, 1, 0, 0, 0, 1, 3, 7, 13, -100, -2, 11, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, -100, -1, 7, 0, 0, 0, 0, 0, 0, 3, 9, 11, 9, 3, 0, 0, 0, 0, 13, -100, 9, 0, 0, 0, 0, 0, 0, 3, -5, 3, 0, 0, 0, 7, -100, 5, 0, 0, 0, 0, 0, 1, 13, -5, 9, 0, 0, 0, 1, -100, 7, 0, 0, 0, 0, 1, 13, -6, 13, 0, 0, 0, 0, -100, -1, 9, 1, 0, 5, 13, -8, 0, 0, 0, 0, 13, -100, -14, 0, 0, 0, 0, 11, -100, -14, 0, 0, 0, 0, 11, -100, -14, 0, 0, 0, 0, 11, -100, -12, 13, 5, 0, 0, 0, 0, 11, -100, -8, 13, 9, 5, 1, 0, 0, 0, 0, 0, 0, 11, -100, -4, 13, 7, 3, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 11, -100, -2, 13, 5, 0, 0, 0, 0, 0, 5, 9, 13, -2, 0, 0, 0, 0, 11, -100, -1, 13, 1, 0, 0, 0, 0, 7, -6, 0, 0, 0, 0, 11, -100, 13, 1, 0, 0, 0, 0, 13, -7, 0, 0, 0, 0, 11, -100, 5, 0, 0, 0, 0, 5, -8, 0, 0, 0, 0, 11, -100, 0, 0, 0, 0, 0, 11, -8, 0, 0, 0, 0, 11, -100, 0, 0, 0, 0, 0, 13, -7, 13, 0, 0, 0, 0, 11, -100, 1, 0, 0, 0, 0, -7, 9, 0, 0, 0, 0, 0, 9, -3, 9, -100, 5, 0, 0, 0, 0, 3, 13, -3, 11, 3, 0, 0, 0, 0, 0, 0, 0, 9, 13, 3, 5, -100, 13, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 11, 9, 0, 0, 0, 0, 0, 0, 1, 13, -100, -1, 11, 1, 0, 0, 0, 0, 0, 0, 0, 0, 5, -3, 9, 0, 0, 0, 0, 0, 11, -100, -2, 13, 7, 3, 0, 0, 0, 3, 7, 13, -5, 9, 0, 1, 3, 9, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -101]

const lt1 = [-100, -100, -4, 13, 5, 0, 3, -100, -3, 11, 1, 0, 0, 0, 7, -100, -2, 7, 0, 0, 0, 0, 0, 3, -100, 13, 3, 0, 0, 0, 0, 0, 0, 5, -100, 1, 0, 0, 0, 0, 0, 0, 0, 9, -100, 1, 0, 0, 0, 0, 0, 0, 0, 13, -100, 13, 3, 0, 0, 0, 0, 0, 1, -100, -2, 5, 0, 0, 0, 0, 5, -100, -3, 0, 0, 0, 0, 9, -100, -3, 0, 0, 0, 0, 11, -100, -3, 0, 0, 0, 0, 11, -100, -3, 0, 0, 0, 0, 9, -100, -3, 0, 0, 0, 0, 11, -100, -3, 0, 0, 0, 0, 11, -100, -3, 0, 0, 0, 0, 11, -100, -3, 0, 0, 0, 0, 3, 13, 9, 5, 3, 1, 0, 0, 1, 3, 5, 9, -100, -3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 13, -100, -3, 0, 0, 0, 0, 0, 5, 13, -2, 13, 11, 9, 5, 0, 0, 0, 0, 1, 13, -100, -3, 0, 0, 0, 0, 1, -8, 13, 1, 0, 0, 0, 5, -100, -3, 3, 0, 0, 0, 5, -9, 13, 0, 0, 0, 0, 11, -100, -3, 0, 0, 0, 0, 9, -10, 7, 0, 0, 0, 5, -100, -3, 1, 0, 0, 0, 11, -10, 13, 0, 0, 0, 0, -100, -3, 3, 0, 0, 0, 11, -11, 3, 0, 0, 0, 11, -100, -3, 1, 0, 0, 0, 11, -11, 7, 0, 0, 0, 7, -100, -3, 0, 0, 0, 0, 11, -11, 9, 0, 0, 0, 3, -100, -3, 0, 0, 0, 0, 11, -11, 11, 0, 0, 0, 1, -100, -3, 0, 0, 0, 0, 11, -11, 11, 0, 0, 0, 1, -100, -3, 0, 0, 0, 0, 11, -11, 11, 0, 0, 0, 0, -100, -3, 0, 0, 0, 0, 11, -11, 9, 0, 0, 0, 0, -100, -3, 0, 0, 0, 0, 11, -11, 7, 0, 0, 0, 3, -100, -3, 0, 0, 0, 0, 11, -11, 3, 0, 0, 0, 7, -100, -3, 0, 0, 0, 0, 11, -11, 0, 0, 0, 0, 11, -100, -3, 0, 0, 0, 0, 11, -10, 9, 0, 0, 0, 3, -100, -3, 0, 0, 0, 0, 9, -10, 3, 0, 0, 0, 11, -100, -3, 0, 0, 0, 0, 3, -9, 11, 0, 0, 0, 5, -100, -2, 13, 0, 0, 0, 0, 0, 9, -7, 11, 1, 0, 0, 3, -100, -2, 7, 0, 0, 0, 0, 0, 0, 7, 13, -2, 13, 9, 3, 0, 0, 0, 3, 13, -100, -2, 13, 0, 0, 5, 13, 11, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, -100, -3, 9, 11, -4, 7, 3, 1, 0, 0, 1, 5, 9, 13, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -101]

const lt2 = [-100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -6, 13, 7, 3, 1, 0, 0, 1, 3, 7, 13, -100, -5, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 13, -100, -3, 13, 3, 0, 0, 0, 5, 13, 13, 7, 0, 0, 0, 0, 0, 1, 13, -100, -2, 13, 1, 0, 0, 0, 9, -4, 7, 0, 0, 0, 0, 0, 1, -100, -1, 13, 1, 0, 0, 0, 9, -6, 5, 0, 0, 0, 0, 0, 13, -100, -1, 5, 0, 0, 0, 3, -8, 1, 0, 0, 0, 3, -100, 13, 0, 0, 0, 0, 11, -8, 13, 3, 0, 3, -100, 7, 0, 0, 0, 1, -100, 5, 0, 0, 0, 5, -100, 3, 0, 0, 0, 9, -100, 1, 0, 0, 0, 11, -100, 0, 0, 0, 0, 11, -100, 0, 0, 0, 0, 11, -100, 0, 0, 0, 0, 11, -100, 0, 0, 0, 0, 9, -100, 1, 0, 0, 0, 5, -100, 5, 0, 0, 0, 0, 13, -100, 11, 0, 0, 0, 0, 7, -100, -1, 3, 0, 0, 0, 0, 13, -100, -1, 11, 0, 0, 0, 0, 3, -12, 9, -100, -2, 7, 0, 0, 0, 0, 3, 13, -8, 9, 1, 3, -100, -3, 5, 0, 0, 0, 0, 1, 9, -5, 9, 3, 0, 0, 11, -100, -4, 5, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 11, -100, -5, 9, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 13, -100, -7, 11, 7, 3, 1, 0, 1, 3, 7, 11, -100, -100, -100, -100, -100, -100, -100, -100, -100, -101]

const lt3 = [-100, -100, -100, -100, -18, 11, 3, 0, -100, -16, 13, 3, 0, 0, 0, -100, -14, 9, 3, 0, 0, 0, 0, 0, -100, -13, 3, 0, 0, 0, 0, 0, 0, 0, -100, -13, 0, 0, 0, 0, 0, 0, 0, 0, -100, -13, 9, 1, 0, 0, 0, 0, 0, 0, -100, -15, 13, 5, 0, 0, 0, 0, -100, -17, 1, 0, 0, 0, -100, -17, 3, 0, 0, 0, -100, -17, 1, 0, 0, 0, -100, -17, 0, 0, 0, 0, -100, -16, 13, 0, 0, 0, 0, -100, -16, 13, 0, 0, 0, 0, -100, -6, 11, 5, 3, 1, 0, 0, 1, 5, 9, 13, 13, 0, 0, 0, 0, -100, -4, 13, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, -100, -3, 13, 1, 0, 0, 0, 0, 5, 11, -1, 13, 11, 3, 0, 0, 0, 0, 0, 0, -100, -2, 13, 1, 0, 0, 0, 0, 7, -6, 11, 0, 0, 0, 0, 0, -100, -2, 3, 0, 0, 0, 0, 9, -8, 11, 0, 0, 0, 0, -100, -1, 9, 0, 0, 0, 0, 7, -9, 11, 0, 0, 0, 0, -100, -1, 1, 0, 0, 0, 0, 13, -9, 11, 0, 0, 0, 0, -100, 11, 0, 0, 0, 0, 3, -10, 11, 0, 0, 0, 0, -100, 5, 0, 0, 0, 0, 13, -10, 11, 0, 0, 0, 0, -100, 3, 0, 0, 0, 3, -11, 11, 0, 0, 0, 0, -100, 0, 0, 0, 0, 7, -11, 11, 0, 0, 0, 0, -100, 0, 0, 0, 0, 11, -11, 11, 0, 0, 0, 0, -100, 0, 0, 0, 0, 11, -11, 11, 0, 0, 0, 0, -100, 0, 0, 0, 0, 11, -11, 11, 0, 0, 0, 0, -100, 1, 0, 0, 0, 9, -11, 11, 0, 0, 0, 0, -100, 3, 0, 0, 0, 7, -11, 11, 0, 0, 0, 0, -100, 7, 0, 0, 0, 3, -11, 11, 0, 0, 0, 0, -100, 13, 0, 0, 0, 0, 13, -10, 13, 0, 0, 0, 0, -100, -1, 3, 0, 0, 0, 5, -11, 0, 0, 0, 0, -100, -1, 13, 0, 0, 0, 0, 11, -10, 0, 0, 0, 0, -100, -2, 7, 0, 0, 0, 1, 13, -8, 13, 0, 0, 0, 0, 13, -100, -3, 5, 0, 0, 0, 1, 11, -7, 5, 0, 0, 0, 0, 9, -100, -4, 5, 0, 0, 0, 0, 3, 9, 13, -1, 13, 11, 1, 0, 0, 0, 0, 0, 0, 0, 5, -100, -5, 9, 1, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 1, 13, -100, -7, 9, 3, 1, 0, 0, 3, 7, 13, -1, 11, 1, 0, 1, 5, 7, 11, -100, -18, 13, -100, -100, -100, -100, -100, -100, -100, -100, -101]

const lt4 = [-100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -7, 13, 5, 1, 1, 0, 1, 3, 9, 13, -100, -6, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, -100, -4, 11, 1, 0, 0, 3, 11, -1, 13, 7, 1, 0, 0, 0, 9, -100, -3, 9, 0, 0, 0, 1, 13, -5, 3, 0, 0, 1, -100, -2, 9, 0, 0, 0, 0, 13, -6, 11, 0, 0, 0, 9, -100, -1, 13, 0, 0, 0, 0, 9, -8, 0, 0, 0, 1, -100, -1, 5, 0, 0, 0, 0, 13, -8, 3, 0, 0, 0, 11, -100, -1, 0, 0, 0, 0, 0, -8, 13, 1, 0, 0, 0, 5, -100, 9, 0, 0, 0, 0, 0, 3, 11, -4, 13, 11, 1, 0, 0, 0, 0, 1, -100, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -100, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, -100, 1, 0, 0, 0, 1, 13, -100, 0, 0, 0, 0, 11, -100, 0, 0, 0, 0, 11, -100, 1, 0, 0, 0, 9, -100, 3, 0, 0, 0, 7, -100, 7, 0, 0, 0, 5, -100, 13, 0, 0, 0, 0, 11, -100, -1, 5, 0, 0, 0, 1, 13, -100, -1, 13, 1, 0, 0, 0, 1, 13, -10, 13, 11, -100, -2, 11, 0, 0, 0, 0, 1, 13, -8, 13, 1, 1, -100, -3, 11, 0, 0, 0, 0, 0, 7, 13, -4, 11, 7, 0, 0, 9, -100, -4, 11, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 7, -100, -5, 13, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 9, -100, -7, 13, 7, 3, 0, 0, 0, 1, 5, 9, -100, -100, -100, -100, -100, -100, -100, -100, -100, -101]

const lt5 = [-100, -100, -100, -100, -9, 13, 9, 3, 1, 0, 1, 5, 13, -100, -8, 7, 0, 0, 0, 0, 0, 0, 0, 3, -100, -7, 3, 0, 0, 0, 0, 0, 0, 0, 0, 1, -100, -6, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, -100, -5, 13, 0, 0, 3, 13, 9, 1, 0, 0, 0, 0, 11, -100, -5, 9, 0, 0, 13, -2, 13, 5, 0, 1, 9, -100, -5, 5, 0, 0, -100, -5, 1, 0, 1, -100, -5, 1, 0, 0, -100, -5, 0, 0, 0, -100, -5, 0, 0, 0, 13, -100, -5, 0, 0, 0, 9, -100, -5, 0, 0, 0, 7, -100, -5, 0, 0, 0, 5, -100, -3, 13, 7, 0, 0, 0, 0, 9, -1, 13, 11, 13, -100, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, -100, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, -100, -1, 11, 13, -1, 7, 0, 0, 0, 0, 5, -1, 13, 11, 13, -100, -5, 0, 0, 0, 0, 11, -100, -5, 0, 0, 0, 0, 11, -100, -5, 0, 0, 0, 0, 11, -100, -5, 0, 0, 0, 0, 11, -100, -5, 0, 0, 0, 0, 11, -100, -5, 0, 0, 0, 0, 11, -100, -5, 0, 0, 0, 0, 11, -100, -5, 0, 0, 0, 0, 11, -100, -5, 0, 0, 0, 0, 11, -100, -5, 0, 0, 0, 0, 11, -100, -5, 0, 0, 0, 0, 11, -100, -5, 0, 0, 0, 0, 11, -100, -5, 0, 0, 0, 0, 11, -100, -5, 0, 0, 0, 0, 11, -100, -5, 0, 0, 0, 0, 11, -100, -5, 0, 0, 0, 0, 7, -100, -3, 13, 5, 0, 0, 0, 0, 0, 7, 13, -100, -1, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 11, -100, -1, 7, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 7, 13, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -101]

const lt6 = [-100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -7, 11, 7, 3, 1, 0, 0, 1, 3, 7, 13, -4, 13, 7, 5, 7, 11, -100, -5, 11, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 13, 13, 5, 0, 0, 0, 0, 0, -100, -4, 9, 0, 0, 0, 5, 13, -1, 13, 9, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, -100, -3, 11, 0, 0, 0, 5, -6, 5, 0, 0, 0, 0, 0, 11, 13, 9, 3, 0, 9, -100, -2, 13, 0, 0, 0, 0, 13, -7, 1, 0, 0, 0, 0, 13, -100, -2, 1, 0, 0, 0, 7, -8, 7, 0, 0, 0, 0, 7, -100, -2, 0, 0, 0, 0, 9, -8, 11, 0, 0, 0, 0, 3, -100, -2, 0, 0, 0, 0, 11, -9, 0, 0, 0, 0, 1, -100, -2, 0, 0, 0, 0, 11, -9, 0, 0, 0, 0, 0, -100, -2, 0, 0, 0, 0, 9, -8, 13, 0, 0, 0, 0, 1, -100, -2, 3, 0, 0, 0, 5, -8, 9, 0, 0, 0, 0, 7, -100, -2, 13, 1, 0, 0, 0, 13, -7, 5, 0, 0, 0, 0, 13, -100, -3, 11, 0, 0, 0, 3, 13, -5, 7, 0, 0, 0, 0, 11, -100, -4, 7, 0, 0, 0, 1, 9, 13, -1, 13, 7, 0, 0, 0, 1, 11, -100, -4, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 13, -100, -4, 13, 0, 0, 0, 0, 0, 0, 1, 3, 5, 9, -100, -2, 13, 5, 0, 11, -100, -1, 13, 1, 0, 0, -100, -1, 3, 0, 0, 0, 1, 7, 13, -100, -1, 0, 0, 0, 0, 0, 0, 0, 1, 3, 7, 9, 11, 13, -100, -1, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 5, 11, -100, -2, 11, 7, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 11, -100, -4, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, -100, -3, 9, 1, 0, 3, 9, 13, 13, 11, 7, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13, -100, -1, 7, 1, 0, 0, 9, -8, 11, 7, 3, 0, 0, 0, 0, 0, 5, -100, 9, 0, 0, 0, 3, -13, 11, 1, 0, 0, 1, -100, 1, 0, 0, 0, 9, -15, 0, 0, 0, -100, 0, 0, 0, 0, 9, -14, 13, 0, 0, 1, -100, 3, 0, 0, 0, 1, -14, 7, 0, 0, 5, -100, 11, 0, 0, 0, 0, 5, -12, 11, 0, 0, 0, 13, -100, -1, 11, 1, 0, 0, 0, 1, 7, 11, 13, -1, 13, 13, 11, 9, 5, 3, 1, 0, 0, 3, 13, -100, -3, 9, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 9, -100, -6, 9, 7, 3, 1, 1, 0, 0, 1, 1, 3, 7, 11, -100, -101]

const lt7 = [-100, -100, -100, -100, -4, 13, 7, 1, 9, -100, -2, 13, 7, 0, 0, 0, 3, -100, -1, 7, 0, 0, 0, 0, 0, 5, -100, 1, 0, 0, 0, 0, 0, 0, 7, -100, 3, 0, 0, 0, 0, 0, 0, 7, -100, 13, 7, 0, 0, 0, 0, 0, 9, -100, -2, 5, 0, 0, 0, 0, 9, -100, -2, 11, 0, 0, 0, 0, 9, -100, -3, 0, 0, 0, 0, 9, -100, -3, 0, 0, 0, 0, 11, -100, -3, 0, 0, 0, 0, 11, -100, -3, 0, 0, 0, 0, 11, -100, -3, 0, 0, 0, 0, 11, -100, -3, 0, 0, 0, 0, 11, -100, -3, 0, 0, 0, 0, 11, -5, 11, 5, 1, 0, 1, 7, -100, -3, 0, 0, 0, 0, 11, -3, 13, 3, 0, 0, 0, 0, 0, 0, 3, -100, -3, 0, 0, 0, 0, 11, -2, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, -100, -3, 0, 0, 0, 0, 11, 11, 3, 0, 5, 11, -1, 13, 9, 1, 0, 0, 0, 3, -100, -3, 0, 0, 0, 0, 3, 0, 1, 11, -6, 1, 0, 0, 0, 13, -100, -3, 0, 0, 0, 0, 0, 5, -8, 11, 0, 0, 0, 11, -100, -3, 0, 0, 0, 0, 11, -10, 0, 0, 0, 7, -100, -3, 0, 0, 0, 0, 13, -10, 0, 0, 0, 7, -100, -3, 0, 0, 0, 0, 11, -10, 0, 0, 0, 7, -100, -3, 0, 0, 0, 0, 11, -10, 0, 0, 0, 7, -100, -3, 0, 0, 0, 0, 13, -10, 0, 0, 0, 9, -100, -3, 0, 0, 0, 0, 13, -10, 0, 0, 0, 9, -100, -3, 0, 0, 0, 0, -11, 0, 0, 0, 11, -100, -3, 0, 0, 0, 1, -11, 0, 0, 0, 13, -100, -3, 0, 0, 0, 1, -11, 0, 0, 0, 13, -100, -3, 0, 0, 0, 3, -11, 0, 0, 0, -100, -3, 0, 0, 0, 3, -11, 0, 0, 0, -100, -3, 0, 0, 0, 3, -11, 0, 0, 0, -100, -3, 0, 0, 0, 3, -10, 13, 0, 0, 0, 13, -100, -3, 0, 0, 0, 1, -10, 13, 0, 0, 0, 11, -100, -2, 9, 0, 0, 0, 0, -10, 11, 0, 0, 0, 5, -100, -1, 7, 0, 0, 0, 0, 0, 5, 13, -7, 13, 3, 0, 0, 0, 0, 7, -100, 5, 0, 0, 0, 0, 0, 0, 0, 0, 3, -5, 1, 0, 0, 0, 0, 0, 0, 1, 3, 11, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -101]

const lt8 = [-100, -100, -100, -100, -3, 5, 1, 0, 3, 11, -100, -2, 7, 0, 0, 0, 0, 0, 11, -100, -2, 1, 0, 0, 0, 0, 0, 5, -100, -2, 0, 0, 0, 0, 0, 0, 5, -100, -2, 5, 0, 0, 0, 0, 0, 11, -100, -3, 7, 0, 0, 3, 9, -100, -4, 13, -100, -100, -100, -100, -100, -100, -100, -4, 11, 3, 0, 9, -100, -2, 9, 3, 0, 0, 0, 9, -100, 11, 1, 0, 0, 0, 0, 0, 7, -100, 1, 0, 0, 0, 0, 0, 0, 7, -100, 1, 0, 0, 0, 0, 0, 0, 9, -100, -1, 11, 0, 0, 0, 0, 0, 9, -100, -2, 7, 0, 0, 0, 0, 11, -100, -3, 0, 0, 0, 0, 13, -100, -3, 1, 0, 0, 0, -100, -3, 1, 0, 0, 0, 13, -100, -3, 1, 0, 0, 0, 13, -100, -3, 0, 0, 0, 0, 11, -100, -3, 0, 0, 0, 0, 11, -100, -3, 0, 0, 0, 0, 11, -100, -3, 0, 0, 0, 0, 11, -100, -3, 0, 0, 0, 0, 11, -100, -3, 0, 0, 0, 0, 11, -100, -3, 0, 0, 0, 0, 11, -100, -3, 0, 0, 0, 0, 11, -100, -2, 13, 0, 0, 0, 0, 7, -100, -2, 13, 0, 0, 0, 0, 1, -100, -2, 7, 0, 0, 0, 0, 0, 9, -100, 7, 0, 0, 0, 0, 0, 0, 0, 0, 3, -100, 9, 5, 1, 1, 0, 0, 1, 1, 3, 5, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -101]

const lt9 = [-100, -100, -100, -100, -6, 5, 0, 1, 5, 13, -100, -5, 5, 0, 0, 0, 0, 1, -100, -5, 1, 0, 0, 0, 0, 0, 13, -100, -5, 0, 0, 0, 0, 0, 0, -100, -5, 5, 0, 0, 0, 0, 3, -100, -6, 7, 1, 0, 5, 13, -100, -100, -100, -100, -100, -100, -100, -100, -6, 13, 7, 3, 0, 13, -100, -5, 7, 0, 0, 0, 0, 11, -100, -3, 7, 1, 0, 0, 0, 0, 0, 11, -100, -2, 13, 0, 0, 0, 0, 0, 0, 0, 11, -100, -3, 11, 3, 0, 0, 0, 0, 0, 11, -100, -5, 9, 0, 0, 0, 0, 11, -100, -6, 1, 0, 0, 0, 11, -100, -6, 3, 0, 0, 0, 11, -100, -6, 5, 0, 0, 0, 11, -100, -6, 5, 0, 0, 0, 11, -100, -6, 5, 0, 0, 0, 11, -100, -6, 5, 0, 0, 0, 11, -100, -6, 3, 0, 0, 0, 11, -100, -6, 3, 0, 0, 0, 11, -100, -6, 1, 0, 0, 0, 11, -100, -6, 1, 0, 0, 0, 13, -100, -6, 1, 0, 0, 0, 13, -100, -6, 1, 0, 0, 0, 13, -100, -6, 1, 0, 0, 0, 13, -100, -6, 1, 0, 0, 0, 13, -100, -6, 1, 0, 0, 0, -100, -6, 1, 0, 0, 0, -100, -6, 1, 0, 0, 1, -100, -6, 1, 0, 0, 3, -100, -6, 0, 0, 0, 5, -100, -6, 0, 0, 0, 7, -100, -6, 0, 0, 0, 11, -100, 11, 0, 0, 0, 5, 5, 0, 0, 5, -100, 3, 0, 0, 0, 0, 0, 0, 3, -100, 0, 0, 0, 0, 0, 0, 0, 13, -100, 1, 0, 0, 0, 0, 0, 11, -100, 13, 3, 0, 0, 3, 11, -100, -100, -101]

const lt10 = [-100, -100, -100, -100, -6, 9, 1, 13, -100, -3, 13, 5, 0, 0, 0, 11, -100, -1, 13, 5, 0, 0, 0, 0, 0, 11, -100, 13, 1, 0, 0, 0, 0, 0, 0, 11, -100, 3, 0, 0, 0, 0, 0, 0, 0, 11, -100, 11, 3, 0, 0, 0, 0, 0, 0, 11, -100, -2, 13, 0, 0, 0, 0, 0, 11, -100, -3, 9, 0, 0, 0, 0, 11, -100, -4, 0, 0, 0, 0, 11, -100, -4, 0, 0, 0, 0, 11, -100, -4, 0, 0, 0, 0, 11, -100, -4, 0, 0, 0, 0, 11, -100, -4, 0, 0, 0, 0, 11, -100, -4, 0, 0, 0, 0, 11, -100, -4, 0, 0, 0, 0, 11, -100, -4, 0, 0, 0, 0, 11, -7, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, -100, -4, 0, 0, 0, 0, 11, -7, 5, 0, 0, 0, 0, 0, 0, 0, 1, 7, 13, -100, -4, 0, 0, 0, 0, 11, -8, 9, 0, 0, 0, 1, 9, -100, -4, 0, 0, 0, 0, 11, -7, 13, 1, 0, 0, 7, -100, -4, 0, 0, 0, 0, 11, -7, 5, 0, 3, 13, -100, -4, 0, 0, 0, 0, 11, -6, 5, 0, 5, -100, -4, 0, 0, 0, 0, 11, -5, 5, 1, 11, -100, -4, 0, 0, 0, 0, 11, -3, 11, 3, 1, -100, -4, 0, 0, 0, 0, 11, -1, 11, 3, 0, 0, 1, -100, -4, 0, 0, 0, 0, 11, 9, 0, 0, 0, 0, 0, 11, -100, -4, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 3, -100, -4, 0, 0, 0, 0, 0, 9, -1, 11, 1, 0, 0, 0, 9, -100, -4, 0, 0, 0, 0, 5, -4, 3, 0, 0, 0, 11, -100, -4, 0, 0, 0, 0, 11, -4, 13, 1, 0, 0, 0, 13, -100, -4, 0, 0, 0, 0, 11, -5, 11, 0, 0, 0, 1, 13, -100, -4, 0, 0, 0, 0, 11, -6, 3, 0, 0, 0, 3, -100, -4, 0, 0, 0, 0, 11, -6, 11, 0, 0, 0, 0, 7, -100, -4, 0, 0, 0, 0, 11, -7, 3, 0, 0, 0, 0, 7, -100, -3, 13, 0, 0, 0, 0, 11, -7, 13, 0, 0, 0, 0, 0, 7, -100, -2, 13, 3, 0, 0, 0, 0, 7, -7, 9, 0, 0, 0, 0, 0, 0, 3, 11, -100, -1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, -4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, -100, -1, 7, 1, 0, 0, 0, 0, 0, 0, 0, 0, 7, -4, 3, 0, 0, 0, 0, 0, 0, 1, 1, 5, 9, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -101]

const lt11 = [-100, -100, -100, -6, 11, 7, 11, -100, -4, 11, 3, 0, 0, 5, -100, -3, 5, 0, 0, 0, 0, 5, -100, -1, 11, 1, 0, 0, 0, 0, 0, 7, -100, 7, 0, 0, 0, 0, 0, 0, 0, 7, -100, 0, 0, 0, 0, 0, 0, 0, 0, 9, -100, 7, 0, 0, 0, 0, 0, 0, 0, 9, -100, -2, 9, 1, 0, 0, 0, 0, 9, -100, -3, 11, 0, 0, 0, 0, 11, -100, -4, 0, 0, 0, 0, 11, -100, -4, 0, 0, 0, 0, 11, -100, -4, 0, 0, 0, 0, 11, -100, -4, 0, 0, 0, 0, 11, -100, -4, 0, 0, 0, 0, 11, -100, -4, 0, 0, 0, 0, 11, -100, -4, 0, 0, 0, 0, 11, -100, -4, 0, 0, 0, 0, 11, -100, -4, 0, 0, 0, 0, 11, -100, -4, 0, 0, 0, 0, 11, -100, -4, 0, 0, 0, 0, 11, -100, -4, 0, 0, 0, 0, 11, -100, -4, 0, 0, 0, 0, 11, -100, -4, 0, 0, 0, 0, 11, -100, -4, 0, 0, 0, 0, 11, -100, -4, 0, 0, 0, 0, 11, -100, -4, 0, 0, 0, 0, 11, -100, -4, 0, 0, 0, 0, 11, -100, -4, 0, 0, 0, 0, 11, -100, -4, 0, 0, 0, 0, 11, -100, -4, 0, 0, 0, 0, 11, -100, -4, 0, 0, 0, 0, 11, -100, -4, 0, 0, 0, 0, 11, -100, -4, 0, 0, 0, 0, 11, -100, -4, 0, 0, 0, 0, 11, -100, -4, 0, 0, 0, 0, 7, -100, -3, 5, 0, 0, 0, 0, 0, 13, -100, -1, 9, 1, 0, 0, 0, 0, 0, 0, 0, 1, 9, -100, -1, 5, 1, 0, 0, 0, 0, 0, 0, 0, 1, 11, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -101]

const lt12 = [-100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -5, 11, 5, 0, -21, 7, 1, 0, 3, 9, -100, -4, 7, 0, 0, 0, 13, -4, 11, 5, 1, 1, 0, 1, 7, -7, 11, 3, 0, 0, 0, 0, 0, 5, -100, -2, 11, 1, 0, 0, 0, 0, 11, -2, 9, 1, 0, 0, 0, 0, 0, 0, 0, 9, -4, 13, 5, 0, 0, 0, 0, 0, 0, 0, 0, 7, -100, 13, 3, 0, 0, 0, 0, 0, 0, 7, 13, 3, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 7, -1, 13, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, -100, 3, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 5, 11, -3, 11, 0, 0, 0, 0, 0, 0, 0, 3, 9, 13, 13, -3, 7, 0, 0, 0, 0, 5, -100, 13, 3, 0, 0, 0, 0, 0, 0, 0, 7, 13, -6, 3, 0, 0, 0, 0, 0, 9, -8, 5, 0, 0, 0, 1, -100, -2, 11, 0, 0, 0, 0, 0, 3, -8, 9, 0, 0, 0, 0, 7, -9, 11, 0, 0, 0, 0, -100, -3, 3, 0, 0, 0, 0, 7, -8, 13, 0, 0, 0, 0, -10, 11, 0, 0, 0, 0, -100, -3, 7, 0, 0, 0, 0, 11, -9, 0, 0, 0, 0, -10, 11, 0, 0, 0, 1, -100, -3, 11, 0, 0, 0, 0, 11, -9, 0, 0, 0, 0, -10, 11, 0, 0, 0, 3, -100, -3, 13, 0, 0, 0, 0, 11, -8, 13, 0, 0, 0, 0, -10, 11, 0, 0, 0, 5, -100, -3, 13, 0, 0, 0, 0, 11, -8, 11, 0, 0, 0, 0, -10, 11, 0, 0, 0, 5, -100, -4, 0, 0, 0, 0, 13, -8, 9, 0, 0, 0, 0, -10, 11, 0, 0, 0, 5, -100, -4, 0, 0, 0, 0, 13, -8, 11, 0, 0, 0, 0, -10, 11, 0, 0, 0, 3, -100, -4, 0, 0, 0, 0, 13, -8, 11, 0, 0, 0, 0, -10, 11, 0, 0, 0, 0, -100, -3, 13, 0, 0, 0, 1, -9, 13, 0, 0, 0, 0, -10, 11, 0, 0, 0, 0, -100, -3, 11, 0, 0, 0, 13, -10, 0, 0, 0, 0, -10, 11, 0, 0, 0, 0, -100, -4, 0, 0, 0, 11, -10, 0, 0, 0, 0, -10, 11, 0, 0, 0, 0, -100, -3, 13, 0, 0, 0, 3, -9, 13, 0, 0, 0, 0, 13, -9, 9, 0, 0, 0, 0, -100, -3, 7, 0, 0, 0, 0, 13, -8, 11, 0, 0, 0, 0, 11, -9, 7, 0, 0, 0, 0, 13, -100, -3, 3, 0, 0, 0, 0, 9, -8, 5, 0, 0, 0, 0, 5, -9, 5, 0, 0, 0, 0, 7, -100, -1, 13, 3, 0, 0, 0, 0, 0, 1, 11, -6, 9, 0, 0, 0, 0, 0, 0, 3, -7, 11, 1, 0, 0, 0, 0, 1, 13, -100, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, -4, 3, 0, 0, 0, 0, 0, 0, 0, 0, 5, -5, 1, 0, 0, 0, 0, 0, 0, 0, 0, 9, -100, 13, 1, 0, 0, 0, 0, 0, 0, 0, 1, 9, -4, 1, 0, 0, 0, 0, 0, 0, 0, 1, 5, -5, 1, 0, 0, 0, 0, 0, 0, 0, 0, 7, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -101]

const lt13 = [-100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -3, 13, 7, 3, 0, 13, -5, 13, 7, 1, 0, 0, 3, 7, -100, -2, 5, 0, 0, 0, 0, -4, 13, 3, 0, 0, 0, 0, 0, 0, 0, 7, -100, 7, 1, 0, 0, 0, 0, 0, -3, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13, -100, 1, 0, 0, 0, 0, 0, 0, 13, 9, 1, 0, 5, 11, 13, -1, 11, 3, 0, 0, 0, 0, 9, -100, 13, 3, 0, 0, 0, 0, 0, 1, 1, 7, -7, 3, 0, 0, 0, 3, -100, -2, 1, 0, 0, 0, 0, 7, -9, 13, 0, 0, 0, 1, -100, -2, 7, 0, 0, 0, 0, -11, 1, 0, 0, 0, -100, -2, 9, 0, 0, 0, 0, -11, 1, 0, 0, 0, 13, -100, -2, 11, 0, 0, 0, 0, -11, 3, 0, 0, 0, 13, -100, -2, 11, 0, 0, 0, 0, -11, 5, 0, 0, 0, 11, -100, -2, 11, 0, 0, 0, 0, -11, 3, 0, 0, 0, 11, -100, -2, 11, 0, 0, 0, 0, -11, 1, 0, 0, 0, 11, -100, -2, 11, 0, 0, 0, 0, -11, 0, 0, 0, 0, 11, -100, -2, 11, 0, 0, 0, 0, -11, 0, 0, 0, 0, 11, -100, -2, 11, 0, 0, 0, 0, -11, 1, 0, 0, 0, 11, -100, -2, 11, 0, 0, 0, 0, -11, 3, 0, 0, 0, 11, -100, -2, 11, 0, 0, 0, 0, -11, 3, 0, 0, 0, 11, -100, -2, 11, 0, 0, 0, 0, 13, -10, 5, 0, 0, 0, 11, -100, -2, 11, 0, 0, 0, 0, 13, -10, 5, 0, 0, 0, 11, -100, -2, 11, 0, 0, 0, 0, 9, -10, 5, 0, 0, 0, 9, -100, -2, 7, 0, 0, 0, 0, 5, -10, 3, 0, 0, 0, 7, -100, -1, 13, 1, 0, 0, 0, 0, 1, 11, -7, 11, 5, 0, 0, 0, 0, 0, 3, 9, -100, -1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 3, -4, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, -100, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, -4, 5, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -101]

const lt14 = [-100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -7, 13, 7, 3, 1, 0, 0, 1, 5, 9, -100, -6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 7, -100, -4, 11, 1, 0, 0, 1, 9, 13, -1, 13, 11, 5, 0, 0, 0, 3, 13, -100, -3, 11, 0, 0, 0, 3, 13, -6, 13, 1, 0, 0, 0, 13, -100, -2, 11, 0, 0, 0, 1, 13, -8, 13, 0, 0, 0, 5, -100, -2, 0, 0, 0, 0, 9, -10, 5, 0, 0, 0, 11, -100, -1, 7, 0, 0, 0, 1, -11, 13, 0, 0, 0, 1, -100, -1, 1, 0, 0, 0, 5, -12, 1, 0, 0, 0, 9, -100, 11, 0, 0, 0, 0, 11, -12, 5, 0, 0, 0, 3, -100, 7, 0, 0, 0, 0, 13, -12, 9, 0, 0, 0, 0, -100, 3, 0, 0, 0, 0, 13, -12, 11, 0, 0, 0, 0, -100, 1, 0, 0, 0, 0, -13, 11, 0, 0, 0, 1, -100, 0, 0, 0, 0, 0, -13, 11, 0, 0, 0, 1, -100, 0, 0, 0, 0, 0, 13, -12, 11, 0, 0, 0, 0, -100, 1, 0, 0, 0, 0, 13, -12, 9, 0, 0, 0, 1, -100, 5, 0, 0, 0, 0, 11, -12, 5, 0, 0, 0, 3, -100, 9, 0, 0, 0, 0, 9, -12, 3, 0, 0, 0, 7, -100, -1, 1, 0, 0, 0, 5, -12, 0, 0, 0, 0, 11, -100, -1, 9, 0, 0, 0, 3, -11, 13, 0, 0, 0, 3, -100, -2, 3, 0, 0, 0, 13, -10, 7, 0, 0, 0, 11, -100, -2, 13, 1, 0, 0, 3, -9, 13, 0, 0, 0, 7, -100, -3, 13, 1, 0, 0, 3, 13, -6, 13, 1, 0, 0, 5, -100, -4, 13, 1, 0, 0, 1, 7, 13, -3, 9, 0, 0, 0, 7, -100, -6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 11, -100, -7, 13, 7, 3, 0, 0, 0, 0, 3, 11, -100, -100, -100, -100, -100, -100, -100, -100, -100, -101]

const lt15 = [-100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -6, 11, 7, -100, -4, 11, 3, 0, 0, 7, 11, 5, 3, 0, 0, 0, 1, 5, 9, -100, -2, 11, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, -100, 13, 5, 0, 0, 0, 0, 0, 0, 0, 1, 7, 11, 13, -1, 13, 3, 0, 0, 0, 5, -100, 1, 0, 0, 0, 0, 0, 0, 0, 3, -7, 7, 0, 0, 0, 7, -100, 1, 0, 0, 0, 0, 0, 0, 0, 11, -8, 7, 0, 0, 0, 13, -100, -1, 11, 5, 0, 0, 0, 0, 0, 11, -9, 1, 0, 0, 3, -100, -3, 7, 0, 0, 0, 0, 11, -9, 5, 0, 0, 0, 11, -100, -3, 9, 0, 0, 0, 0, 11, -9, 9, 0, 0, 0, 5, -100, -3, 11, 0, 0, 0, 0, 11, -9, 11, 0, 0, 0, 0, 13, -100, -3, 11, 0, 0, 0, 0, 11, -9, 13, 0, 0, 0, 0, 11, -100, -3, 13, 0, 0, 0, 0, 11, -10, 0, 0, 0, 0, 11, -100, -3, 13, 0, 0, 0, 0, 11, -10, 0, 0, 0, 0, 11, -100, -3, 13, 0, 0, 0, 0, 11, -10, 0, 0, 0, 0, 11, -100, -4, 0, 0, 0, 0, 11, -10, 0, 0, 0, 0, 13, -100, -4, 0, 0, 0, 0, 11, -10, 0, 0, 0, 0, 13, -100, -4, 0, 0, 0, 0, 13, -10, 0, 0, 0, 0, -100, -4, 0, 0, 0, 9, -11, 0, 0, 0, 3, -100, -4, 0, 0, 0, 3, -11, 0, 0, 0, 9, -100, -4, 0, 0, 0, 0, 13, -10, 0, 0, 0, 13, -100, -4, 0, 0, 0, 0, 11, -9, 5, 0, 0, 0, -100, -4, 0, 0, 0, 0, 11, -8, 7, 0, 0, 0, 7, -100, -4, 0, 0, 0, 0, 5, -7, 9, 0, 0, 0, 3, -100, -4, 0, 0, 0, 0, 0, 3, 11, 13, -3, 9, 0, 0, 0, 1, -100, -4, 0, 0, 0, 0, 5, 7, 0, 0, 0, 1, 1, 0, 0, 0, 1, 13, -100, -4, 0, 0, 0, 0, 11, -2, 9, 5, 1, 0, 0, 3, 7, -100, -4, 0, 0, 0, 0, 11, -100, -4, 0, 0, 0, 0, 11, -100, -4, 0, 0, 0, 0, 11, -100, -4, 0, 0, 0, 0, 7, -100, -4, 0, 0, 0, 0, 3, -100, -3, 7, 0, 0, 0, 0, 0, 9, -100, -1, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, -100, -1, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, -100, -101]

const lt16 = [-100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -19, 7, 11, -100, -6, 11, 5, 1, 0, 0, 1, 5, 11, -4, 5, 0, 3, -100, -4, 13, 3, 0, 0, 0, 0, 0, 0, 0, 0, 1, 11, 13, 5, 0, 0, 1, -100, -3, 13, 1, 0, 0, 1, 5, 11, -3, 11, 3, 0, 0, 0, 0, 0, 3, -100, -2, 13, 1, 0, 0, 3, -8, 3, 0, 0, 0, 0, 5, -100, -1, 13, 1, 0, 0, 0, 13, -8, 7, 0, 0, 0, 0, 5, -100, -1, 3, 0, 0, 0, 5, -9, 11, 0, 0, 0, 0, 7, -100, 9, 0, 0, 0, 0, 11, -9, 13, 0, 0, 0, 0, 9, -100, 3, 0, 0, 0, 0, -10, 13, 0, 0, 0, 0, 9, -100, 1, 0, 0, 0, 1, -11, 0, 0, 0, 0, 9, -100, 0, 0, 0, 0, 3, -11, 0, 0, 0, 0, 11, -100, 0, 0, 0, 0, 5, -11, 0, 0, 0, 0, 11, -100, 0, 0, 0, 0, 9, -11, 0, 0, 0, 0, 11, -100, 0, 0, 0, 0, 11, -11, 0, 0, 0, 0, 11, -100, 0, 0, 0, 0, 11, -11, 0, 0, 0, 0, 11, -100, 1, 0, 0, 0, 11, -11, 0, 0, 0, 0, 11, -100, 3, 0, 0, 0, 9, -11, 0, 0, 0, 0, 11, -100, 7, 0, 0, 0, 5, -11, 0, 0, 0, 0, 11, -100, 11, 0, 0, 0, 0, -11, 0, 0, 0, 0, 11, -100, -1, 1, 0, 0, 0, 7, -9, 11, 0, 0, 0, 0, 11, -100, -1, 9, 0, 0, 0, 0, 13, -8, 9, 0, 0, 0, 0, 11, -100, -2, 3, 0, 0, 0, 1, 13, -7, 5, 0, 0, 0, 0, 11, -100, -2, 13, 3, 0, 0, 0, 1, 9, 13, -3, 13, 7, 0, 0, 0, 0, 0, 11, -100, -4, 9, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 11, -100, -6, 11, 7, 3, 1, 0, 0, 5, 9, -1, 13, 0, 0, 0, 0, 11, -100, -16, 0, 0, 0, 0, 13, -100, -16, 0, 0, 0, 0, 13, -100, -16, 0, 0, 0, 0, 13, -100, -16, 0, 0, 0, 0, 13, -100, -15, 13, 0, 0, 0, 0, 13, -100, -15, 9, 0, 0, 0, 0, 11, -100, -15, 1, 0, 0, 0, 0, 5, -100, -12, 7, 5, 1, 0, 0, 0, 0, 0, 0, 1, 3, 9, -100, -11, 13, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, -100, -101]

const lt17 = [-100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -3, 13, 5, 0, 3, -5, 9, 3, 1, 0, 0, 3, -100, -1, 11, 3, 0, 0, 0, 0, -3, 7, 0, 0, 0, 0, 0, 0, 0, 5, -100, 9, 0, 0, 0, 0, 0, 0, -2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 1, -100, 0, 0, 0, 0, 0, 0, 0, 11, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, -100, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, -100, -1, 7, 0, 0, 0, 0, 0, 0, 7, 13, -2, 11, 7, 3, 1, 3, 11, -100, -2, 3, 0, 0, 0, 0, 3, -100, -2, 7, 0, 0, 0, 0, 9, -100, -2, 11, 0, 0, 0, 0, 13, -100, -2, 13, 0, 0, 0, 0, -100, -3, 0, 0, 0, 0, -100, -3, 0, 0, 0, 0, 13, -100, -3, 0, 0, 0, 0, 13, -100, -3, 0, 0, 0, 0, 13, -100, -3, 0, 0, 0, 0, 11, -100, -3, 0, 0, 0, 0, 11, -100, -3, 0, 0, 0, 0, 11, -100, -3, 0, 0, 0, 0, 11, -100, -3, 0, 0, 0, 0, 11, -100, -3, 0, 0, 0, 0, 11, -100, -3, 0, 0, 0, 0, 9, -100, -1, 13, 3, 0, 0, 0, 0, 1, 13, -100, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13, -100, 5, 1, 0, 0, 0, 0, 0, 0, 0, 0, 3, 13, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -101]

const lt18 = [-100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -3, 13, 7, 1, 0, 1, 3, 9, 11, 9, 9, 13, -100, -2, 13, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, -100, -2, 1, 0, 5, 13, -1, 13, 11, 3, 0, 0, 0, 1, -100, -1, 9, 0, 1, -6, 9, 0, 0, 0, 13, -100, -1, 3, 0, 9, -7, 11, 1, 0, 9, -100, -1, 0, 0, -9, 13, 1, 5, -100, -1, 0, 0, 11, -9, 13, 11, -100, 13, 0, 0, 1, 13, -100, 13, 0, 0, 0, 1, 9, -100, -1, 0, 0, 0, 0, 0, 0, 5, 9, -100, -1, 5, 0, 0, 0, 0, 0, 0, 0, 1, 7, 13, -100, -1, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, -100, -2, 13, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, -100, -4, 11, 5, 0, 0, 0, 0, 0, 0, 0, 0, 7, -100, -7, 9, 5, 0, 0, 0, 0, 0, 0, 13, -100, -9, 13, 7, 0, 0, 0, 0, 7, -100, -11, 13, 3, 0, 0, 3, -100, -13, 0, 0, 0, -100, 7, 5, -11, 1, 0, 0, -100, 1, 0, 5, -10, 1, 0, 3, -100, 0, 0, 0, 3, -9, 0, 0, 9, -100, 1, 0, 0, 0, 3, 13, -6, 5, 0, 3, -100, 7, 0, 0, 0, 0, 1, 7, 11, 13, 13, 9, 3, 0, 1, 13, -100, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 13, -100, -1, 5, 3, 9, 7, 3, 1, 0, 0, 1, 5, 11, -100, -100, -100, -100, -100, -100, -100, -100, -100, -101]

const lt19 = [-100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -6, 5, 0, 5, -100, -5, 13, 0, 0, 0, 7, -100, -5, 7, 0, 0, 0, 9, -100, -5, 3, 0, 0, 0, 13, -100, -4, 11, 0, 0, 0, 0, -100, -4, 3, 0, 0, 0, 0, -100, -3, 5, 0, 0, 0, 0, 1, -100, -2, 3, 0, 0, 0, 0, 0, 7, -100, 13, 1, 0, 0, 0, 0, 0, 0, 1, 11, -100, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 13, -100, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, -100, -3, 9, 0, 0, 0, 0, 7, 13, -100, -4, 0, 0, 0, 0, 11, -100, -4, 1, 0, 0, 0, 11, -100, -4, 1, 0, 0, 0, 11, -100, -4, 0, 0, 0, 0, 11, -100, -4, 0, 0, 0, 0, 11, -100, -4, 0, 0, 0, 0, 11, -100, -4, 0, 0, 0, 0, 11, -100, -4, 1, 0, 0, 0, 11, -100, -4, 3, 0, 0, 0, 11, -100, -4, 5, 0, 0, 0, 11, -100, -4, 3, 0, 0, 0, 11, -100, -4, 3, 0, 0, 0, 11, -100, -4, 1, 0, 0, 0, 9, -100, -4, 0, 0, 0, 0, 5, -100, -4, 0, 0, 0, 0, 1, -100, -4, 1, 0, 0, 0, 0, 11, -100, -4, 3, 0, 0, 0, 0, 1, 13, -1, 9, 5, 1, 3, -100, -4, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, -100, -5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 5, -100, -6, 9, 3, 1, 0, 0, 1, 5, 11, -100, -100, -100, -100, -100, -100, -100, -100, -100, -101]

const lt20 = [-100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -4, 13, 9, 1, 0, 13, -11, 11, 5, 1, 5, -100, -2, 11, 3, 0, 0, 0, 0, 11, -8, 11, 5, 0, 0, 0, 0, 1, -100, 13, 3, 0, 0, 0, 0, 0, 0, 11, -6, 7, 1, 0, 0, 0, 0, 0, 0, 7, -100, 5, 0, 0, 0, 0, 0, 0, 0, 11, -5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 11, -100, 11, 1, 0, 0, 0, 0, 0, 0, 11, -5, 9, 0, 0, 0, 0, 0, 0, 0, 0, 11, -100, -2, 11, 1, 0, 0, 0, 0, 11, -6, 13, 7, 3, 0, 0, 0, 0, 0, 11, -100, -3, 9, 0, 0, 0, 0, 11, -9, 9, 0, 0, 0, 0, 11, -100, -3, 11, 0, 0, 0, 0, 11, -10, 0, 0, 0, 0, 11, -100, -3, 13, 0, 0, 0, 0, 11, -10, 0, 0, 0, 0, 11, -100, -4, 0, 0, 0, 0, 11, -10, 0, 0, 0, 0, 11, -100, -4, 0, 0, 0, 0, 11, -10, 0, 0, 0, 0, 11, -100, -4, 0, 0, 0, 0, 11, -10, 0, 0, 0, 0, 11, -100, -4, 0, 0, 0, 0, 11, -10, 0, 0, 0, 0, 11, -100, -4, 0, 0, 0, 0, 11, -10, 0, 0, 0, 0, 11, -100, -4, 0, 0, 0, 0, 11, -10, 0, 0, 0, 0, 11, -100, -4, 0, 0, 0, 0, 11, -10, 0, 0, 0, 0, 11, -100, -4, 0, 0, 0, 0, 11, -10, 0, 0, 0, 0, 11, -100, -4, 1, 0, 0, 0, 11, -9, 13, 0, 0, 0, 0, 11, -100, -4, 1, 0, 0, 0, 11, -9, 5, 0, 0, 0, 0, 11, -100, -4, 5, 0, 0, 0, 7, -8, 7, 0, 0, 0, 0, 0, 11, -100, -4, 7, 0, 0, 0, 0, 13, -5, 13, 5, 0, 0, 0, 0, 0, 0, 11, -100, -4, 13, 0, 0, 0, 0, 1, 11, -1, 13, 11, 5, 0, 0, 7, 5, 0, 0, 0, 0, 3, 13, -100, -5, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 13, -2, 0, 0, 0, 0, 0, 0, 7, -100, -5, 11, 0, 0, 0, 0, 0, 0, 0, 1, 9, -4, 0, 0, 0, 0, 0, 0, 0, -100, -6, 13, 5, 1, 0, 1, 3, 9, -6, 3, 1, 3, 7, 9, 11, 13, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -101]

const lt21 = [-100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -6, 13, 9, 1, 3, 13, -5, 13, 1, 0, 0, 0, 0, 1, 3, 9, -100, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, -5, 1, 0, 0, 0, 0, 0, 0, 0, 0, 9, -100, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, -5, 3, 0, 0, 0, 0, 0, 0, 0, 0, 13, -100, -1, 9, 3, 0, 0, 0, 0, 0, 5, 13, -7, 13, 9, 0, 0, 0, 0, 1, 11, -100, -3, 7, 0, 0, 0, 0, -11, 7, 0, 0, 5, -100, -4, 0, 0, 0, 0, 9, -10, 9, 0, 5, -100, -4, 5, 0, 0, 0, 1, -10, 5, 0, 11, -100, -4, 11, 0, 0, 0, 0, 9, -9, 0, 1, -100, -5, 1, 0, 0, 0, 3, -8, 9, 0, 7, -100, -5, 7, 0, 0, 0, 0, 13, -7, 3, 0, 13, -100, -5, 13, 0, 0, 0, 0, 7, -6, 13, 0, 3, -100, -6, 3, 0, 0, 0, 1, -6, 7, 0, 11, -100, -6, 9, 0, 0, 0, 0, 9, -5, 0, 1, -100, -6, 13, 0, 0, 0, 0, 3, -4, 7, 0, 7, -100, -7, 5, 0, 0, 0, 0, 11, -3, 1, 0, 13, -100, -7, 11, 0, 0, 0, 0, 1, -2, 9, 0, 5, -100, -8, 1, 0, 0, 0, 0, 5, -1, 1, 0, 11, -100, -8, 7, 0, 0, 0, 0, 0, 0, 0, 3, -100, -8, 13, 0, 0, 0, 0, 0, 0, 0, 9, -100, -9, 3, 0, 0, 0, 0, 0, 1, -100, -9, 9, 0, 0, 0, 0, 0, 7, -100, -10, 0, 0, 0, 0, 0, 13, -100, -10, 5, 0, 0, 0, 1, -100, -10, 13, 1, 0, 0, 7, -100, -11, 11, 1, 5, -100, -100, -100, -100, -100, -100, -100, -100, -100, -101]

const lt22 = [-100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -29, 13, -100, 5, 0, 0, 1, 1, 1, 3, 3, 5, 7, -3, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, -4, 3, 0, 0, 0, 0, 0, 0, 1, 3, 11, -100, 5, 0, 0, 0, 0, 0, 0, 0, 1, 7, -3, 9, 0, 0, 0, 0, 0, 0, 0, 0, 1, 11, -4, 9, 1, 0, 0, 0, 0, 0, 0, 1, 13, -100, -1, 13, 5, 0, 0, 0, 0, 0, 13, -5, 13, 5, 0, 0, 0, 0, 0, 3, -8, 9, 0, 0, 0, 0, 5, -100, -3, 5, 0, 0, 0, 0, -8, 11, 0, 0, 0, 0, 9, -9, 9, 0, 0, 9, -100, -4, 1, 0, 0, 0, 13, -8, 11, 0, 0, 0, 3, -10, 0, 3, -100, -4, 7, 0, 0, 0, 11, -8, 13, 0, 0, 0, 0, 13, -8, 9, 0, 11, -100, -4, 13, 0, 0, 0, 7, -8, 11, 0, 0, 0, 0, 7, -8, 1, 1, -100, -5, 5, 0, 0, 1, -8, 7, 0, 0, 0, 0, 3, -8, 5, 11, -100, -5, 11, 0, 0, 0, 9, -7, 1, 0, 0, 0, 0, 0, 13, -100, -6, 0, 0, 0, 3, -6, 9, 0, 3, 13, 0, 0, 0, 7, -6, 5, -100, -6, 3, 0, 0, 0, 13, -5, 1, 0, 11, -1, 3, 0, 0, 3, -6, 1, -100, -6, 9, 0, 0, 0, 9, -4, 11, 0, 3, -2, 7, 0, 0, 0, 13, -4, 11, 1, -100, -6, 13, 0, 0, 0, 3, -4, 5, 0, 9, -2, 13, 0, 0, 0, 7, -4, 5, 3, -100, -7, 3, 0, 0, 0, 13, -3, 1, 1, -4, 0, 0, 0, 1, -4, 1, 7, -100, -7, 9, 0, 0, 0, 5, -2, 13, 0, 7, -4, 5, 0, 0, 0, 9, -2, 9, 0, 13, -100, -8, 1, 0, 0, 0, 13, -1, 7, 1, -5, 11, 0, 0, 0, 1, -2, 1, 3, -100, -8, 7, 0, 0, 0, 1, 13, 1, 5, -6, 1, 0, 0, 0, 13, 9, 0, 9, -100, -8, 13, 0, 0, 0, 0, 0, 0, 11, -6, 7, 0, 0, 0, 1, 0, 1, -100, -9, 3, 0, 0, 0, 0, 3, -7, 13, 0, 0, 0, 0, 0, 9, -100, -9, 9, 0, 0, 0, 0, 5, -8, 3, 0, 0, 0, 0, 13, -100, -9, 13, 0, 0, 0, 0, 11, -8, 9, 0, 0, 0, 1, -100, -10, 3, 0, 0, 0, -10, 3, 0, 0, 5, -100, -10, 11, 0, 0, 7, -10, 13, 1, 1, 13, -100, -11, 11, 11, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -101]

const lt23 = [-100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -16, 13, 13, -1, 13, 9, 5, 1, 0, 1, 5, 13, -100, -1, 3, 0, 0, 0, 0, 0, 0, 0, 0, 1, 7, -4, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, -100, -1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 11, -4, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, -100, -2, 13, 7, 0, 0, 0, 0, 0, 0, 13, -6, 13, 5, 0, 0, 0, 0, 5, 9, 13, -100, -4, 13, 3, 0, 0, 0, 0, 3, -7, 13, 0, 0, 5, 13, -100, -6, 3, 0, 0, 0, 0, 5, -6, 7, 0, 7, -100, -7, 3, 0, 0, 0, 0, 11, -4, 11, 0, 9, -100, -8, 5, 0, 0, 0, 1, -3, 11, 0, 7, -100, -9, 3, 0, 0, 0, 1, 11, 11, 0, 7, -100, -9, 13, 1, 0, 0, 0, 0, 0, 7, -100, -10, 13, 1, 0, 0, 0, 0, 9, -100, -11, 11, 0, 0, 0, 0, 1, -100, -12, 0, 0, 0, 0, 0, 7, -100, -11, 9, 0, 0, 0, 0, 0, 0, 11, -100, -10, 9, 0, 5, 13, 3, 0, 0, 0, 1, 13, -100, -9, 11, 0, 3, -2, 13, 1, 0, 0, 0, 1, 13, -100, -8, 11, 0, 3, 13, -3, 13, 1, 0, 0, 0, 1, 13, -100, -7, 9, 0, 1, 13, -5, 11, 0, 0, 0, 0, 1, 13, -100, -6, 9, 0, 0, 7, -7, 9, 0, 0, 0, 0, 1, 11, -100, -5, 5, 0, 0, 0, 13, -8, 7, 0, 0, 0, 0, 0, 9, -100, -3, 13, 3, 0, 0, 0, 0, 13, -8, 13, 0, 0, 0, 0, 0, 0, 5, -100, 9, 3, 1, 0, 0, 0, 0, 0, 0, 1, 11, -6, 11, 1, 0, 0, 0, 0, 0, 0, 0, 1, 3, 13, -100, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, -6, 11, 5, 3, 1, 0, 0, 0, 1, 1, 3, 5, -100, 13, 13, 13, 13, -100, -100, -100, -100, -100, -100, -100, -100, -100, -101]

const lt24 = [-100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -1, 13, 13, -2, 13, 13, 11, 11, 11, 13, -6, 11, 11, 11, 11, 11, 11, 11, 11, 13, -100, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, -4, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, -100, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, -4, 3, 0, 0, 0, 0, 0, 0, 0, 0, 9, -100, -2, 11, 5, 0, 0, 0, 0, 0, 0, 11, -6, 11, 0, 0, 0, 0, 1, 7, 13, -100, -4, 11, 0, 0, 0, 0, 0, -8, 9, 0, 0, 1, 13, -100, -5, 7, 0, 0, 0, 0, 13, -7, 9, 0, 0, 13, -100, -6, 1, 0, 0, 0, 9, -7, 5, 0, 5, -100, -6, 7, 0, 0, 0, 3, -7, 1, 0, 13, -100, -6, 13, 0, 0, 0, 0, 13, -5, 11, 0, 1, -100, -7, 5, 0, 0, 0, 7, -5, 7, 0, 7, -100, -7, 11, 0, 0, 0, 3, -5, 1, 0, 11, -100, -8, 1, 0, 0, 0, 13, -3, 13, 0, 3, -100, -8, 7, 0, 0, 0, 7, -3, 7, 0, 9, -100, -8, 13, 0, 0, 0, 3, -3, 1, 1, -100, -9, 5, 0, 0, 0, 13, -1, 9, 0, 7, -100, -9, 11, 0, 0, 0, 3, 13, 1, 0, 13, -100, -10, 1, 0, 0, 0, 0, 0, 3, -100, -10, 9, 0, 0, 0, 0, 0, 9, -100, -11, 1, 0, 0, 0, 1, -100, -11, 5, 0, 0, 0, 7, -100, -11, 9, 0, 0, 0, 13, -100, -11, 13, 0, 0, 3, -100, -12, 0, 0, 9, -100, -12, 0, 1, -100, -11, 13, 0, 7, -100, -11, 7, 0, 11, -100, -11, 1, 0, -100, -2, 7, 0, 1, 7, -4, 11, 0, 3, -100, -1, 11, 0, 0, 0, 0, 1, 9, 13, 11, 1, 0, 9, -100, -1, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, -100, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 13, -100, -1, 7, 0, 0, 0, 0, 0, 0, 0, 1, 13, -100, -2, 9, 3, 0, 0, 1, 3, 7, -100, -101]

const lt = [lt0, lt1, lt2, lt3, lt0, lt5, lt0, lt7, lt8, lt9, lt10, lt11, lt12, lt13, lt14, lt15, lt16, lt17, lt18, lt19, lt20, lt21, lt22, lt23, lt24]


@Injectable()
export class GifUtils {

  urandom(size: number): Buffer {
    return randomBytes(size)
  }
  
  random(min, max) {
    return Math.floor(Math.random() * (max - min)) + min
  }
  
  letter(n, pos, im, swr, s1, s2) {
    let l = im.length
    let t = lt[n]
    let r = 200 * 16 + pos
    let i = r
    let sk1 = s1 + pos
    let sk2 = s2 + pos
    let mpos = pos
    let row = 0
  
    for (let j = 0, k = t.length; j < k; j++) {
      let p = t[j]
      if (p === -101) continue
  
      if (p < 0) {
        if (p === -100) {
          r += 200
          i = r
          sk1 = s1 + pos
          row++
          continue
        }
        i += -p
        continue
      }
  
      if (sk1 >= 200) sk1 = sk1 % 200
      let skew = Math.floor(SW[sk1] / 16)
      sk1 += (swr[pos + i - r] & 0x1) + 1
  
      if (sk2 >= 200) sk2 %= 200
      let skewh = Math.floor(SW[sk2] / 70)
      sk2 += swr[row] & 0x1
  
      let x = i + skew * 200 + skewh
      mpos = Math.max(mpos, pos + i - r)
  
      if (x - l < 70 * 200) im[x] = p << 4
      i++
    }
  
    return mpos
  }
  
  line(im, swr, s1) {
    for (let x = 0, sk1 = s1; x < 199; x++) {
      if (sk1 >= 200) sk1 %= 200
      let skew = Math.floor(SW[sk1] / 16)
      sk1 += (swr[x] & 0x3) + 1
      let i = 200 * (45 + skew) + x
      im[i + 0] = 0
      im[i + 1] = 0
      im[i + 200] = 0
      im[i + 201] = 0
    }
  }
  
  dots(im, dr) {
    for (let n = 0; n < NDOTS; n++) {
      let v = dr.readUInt32BE(n)
      let i = v % (200 * 67)
  
      im[i + 0] = 0xff
      im[i + 1] = 0xff
      im[i + 2] = 0xff
      im[i + 200] = 0xff
      im[i + 201] = 0xff
      im[i + 202] = 0xff
    }
  }
  
  blur(im) {
    for (let i = 0, y = 0; y < 68; y++) {
      for (let x = 0; x < 198; x++) {
        let c11 = im[i + 0]
        let c12 = im[i + 1]
        let c21 = im[i + 200]
        let c22 = im[i + 201]
        im[i++] = Math.floor((c11 + c12 + c21 + c22) / 4)
      }
    }
  }
  
  filter(im) {
    const om = Buffer.alloc(70 * 200).fill(0xff)
    let i = 0
    let o = 0
  
    for (let y = 0; y < 70; y++) {
      for (let x = 4; x < 200 - 4; x++) {
        if (im[i] > 0xf0 && im[i + 1] < 0xf0) {
          om[o] = 0
          om[o + 1] = 0
        } else if (im[i] < 0xf0 && im[i + 1] > 0xf0) {
          om[o] = 0
          om[o + 1] = 0
        }
  
        i++
        o++
      }
    }
  
    om.copy(im)
  }
  
  async captcha(size) {
    const rb = await this.urandom(size + 200 + 100 * 4 + 1 + 1)
    const l = Buffer.alloc(size)
    const swr = Buffer.alloc(200)
    const dr = Buffer.alloc(100 * 4)
    let s1
    let s2
  
    rb.copy(l, 0, 0, size)
    rb.copy(swr, 0, size, size + 200)
    rb.copy(dr, 0, size + 200, size + 200 + 100 * 4)
    s1 = rb.readUInt8(size + 200 + 100 * 4)
    s2 = rb.readUInt8(size + 200 + 100 * 4 + 1)
  
    const im = Buffer.alloc(200 * 70).fill(0xff)
  
    s1 &= 0x7f
    s2 &= 0x3f
  
    let p = 30
  
    for (let n = 0; n < size; n++) {
      l[n] %= 25
      p = this.letter(l[n], p, im, swr, s1, s2)
      l[n] = LETTERS.charCodeAt(l[n])
    }
  
    this.line(im, swr, s1)
    this.dots(im, dr)
    // blur(im)
    // filter(im)
  
    return { im, l }
  }
  
  // http://brokestream.com/captcha.html
  makegif(im, gif, style) {
    // tag ; widthxheight ; GCT:0:0:7 ; bgcolor + aspect // GCT
    // Image Separator // left x top // widthxheight // Flags
    // LZW code size
    let r = style === -1 ? this.random(0, colors.length) : style
  
    gif.fill(colors[r].replace(/\n/g, ''), 0, 13 + 48 + 10 + 1, 'ascii')
  
    let i = 0
    let p = 13 + 48 + 10 + 1
    for (let y = 0; y < 70; y++) {
      gif[p++] = 250 // Data length 5*50=250
      for (let x = 0; x < 50; x++) {
        let a = im[i + 0] >> 4
        let b = im[i + 1] >> 4
        let c = im[i + 2] >> 4
        let d = im[i + 3] >> 4
  
        gif[p + 0] = 16 | (a << 5) // bbb10000
        gif[p + 1] = (a >> 3) | 64 | (b << 7) // b10000xb
        gif[p + 2] = b >> 1 // 0000xbbb
        gif[p + 3] = 1 | (c << 1) // 00xbbbb1
        gif[p + 4] = 4 | (d << 3) // xbbbb100
        i += 4
        p += 5
      }
    }
  
    gif.fill('\x01\x11\x00;', GIF_SIZE - 4)
  }
  
  async generate({ size = SIZE, style = -1 } = {}) {
    const gif = Buffer.alloc(GIF_SIZE)
    const { im, l } = await this.captcha(size)
    this.makegif(im, gif, style)
  
    return {
      buffer: gif,
      token: l.toString()
    }
  }
  
}
